package com.pokemon.server;

import com.pokemon.dto.PokemonDTO;
import com.pokemon.services.PokemonService;
import java.util.List;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

/**
 *
 * @author Ladislav
 */
@WebService(endpointInterface="com.pokemon.services.PokemonService", serviceName="Pokemon")
public class PokemonServiceImpl implements PokemonService {
    
    @Resource
    WebServiceContext wsCtx;
   
    PokemonService service;
    
    public PokemonService getService() {
        return service;
    }

    public void setService(PokemonService service) {
        this.service = service;
    }
    
    private String getClient(){
        MessageContext msgCtx = wsCtx.getMessageContext();
        HttpServletRequest req = (HttpServletRequest) msgCtx.get(MessageContext.SERVLET_REQUEST);
        return req.getRemoteHost();
    }
    

    public PokemonDTO addPokemon(PokemonDTO pokemon) {
        service.addPokemon(pokemon);
        return pokemon;
    }

    public PokemonDTO getPokemon(Long id) {
        return service.getPokemon(id);
    }

    public PokemonDTO updatePokemon(PokemonDTO pokemon) {
        service.updatePokemon(pokemon);
        return pokemon;
    }

    public PokemonDTO removePokemon(PokemonDTO pokemon) {
        service.removePokemon(pokemon);
        return pokemon;
    }

    public List<PokemonDTO> getAllPokemons() {
        return service.getAllPokemons();
    }
    
}
